#ifndef CGUIOBJECT_H_
#define CGUIOBJECT_H_

#include "cguirenderer.h"
#include "cguistyle.h"
#include "clayout.h"
#include "clayoutitem.h"
#include "../event/cmouseevent.h"
#include "../exception/cguiborderoverlapexception.h"
#include "../math/crect.h"

// Foward declarations
class CGuiManager;
class CDialog;

/**
 * CGuiObject - abstract class representing gui object
 * @author Michal Rost
 * @date 28.03.2008
 */
class CGuiObject : public CObject {
  friend class CGuiManager;
  friend class CDialog;
public:
  virtual ~CGuiObject();
  int getX() const;
  int getY() const;
  unsigned short getWidth() const;
  unsigned short getHeight() const;
  CGuiStyle getStyle() const;
  CGuiObject* getOwnerPtr() const;
  vector<CLayoutItem*>* getItemsPtr() const;
  CLayoutItem* getItemPtr(TIndex index) const;
  bool isVisible() const;
  bool isDisabled() const;
  void setStyle(CGuiStyle style);
  void setVisible(bool visible);
  void setDisabled(bool disabled);
  static string getClassName() {
    return "CGuiObject";
  }
protected:
  int x, y;
  unsigned short width, height;
  bool visible;
  bool disabled;
  CGuiStyle style;
  CLayout layout;
  CGuiObject* ownerPtr;
  vector<CLayoutItem*>* items;
  void init();
  void free();
  void setX(int x);
  void setY(int y);
  void setWidth(unsigned short width);
  void setHeight(unsigned short height);
  void setOwnerPtr(CGuiObject* ownerPtr);
  void drawBase(CGuiRenderer* rendererPtr);
  void drawBorder(CGuiRenderer* rendererPtr);
  void drawChildren(CGuiRenderer* rendererPtr);
  void setItemXVars(CGuiObject* ptr, TIndex posX, TIndex spanX);
  void setItemYVars(CGuiObject* ptr, TIndex posY, TIndex spanY);
  void addItem(CGuiObject* itemPtr, TIndex posX, TIndex posY,
      TIndex spanX = 1, TIndex spanY = 1);
  virtual void drawSelf(CGuiRenderer* rendererPtr) = 0;
  virtual bool isFocused(CMouseEvent* eventPtr) = 0;
  virtual bool isOverlap(CRect<int> &rect) = 0;
  virtual void onAdd() = 0;
private:
  void draw(CGuiRenderer* rendererPtr);
  CGuiObject* dispatchMouseEvent(CMouseEvent* eventPtr);
};

#endif
